//
//  LLAssetsPickerStyle.m
//  LLCoreUserInterface
//
//  Created by my_liu on 2016/11/16.
//  Copyright © 2016年 my_liu. All rights reserved.
//

#import "LLAssetsPickerStyle.h"
#import "LLQuickUIMacrocDefine.h"

@implementation LLAssetsPickerStyle

#pragma mark - 系统用到的一些配置
+ (UIColor *)sysButtonTitleNormalColor
{
    return LLQuickHexColor(@"343434");
}

+ (UIColor *)sysButtonTitleHighlightColor
{
    return LLQuickHexColor(@"333333");
}

+ (UIFont *)sysButtonFont
{
    return [UIFont systemFontOfSize:16];
}

+ (UIFont *)sysNavigationTitleFont
{
    return [UIFont boldSystemFontOfSize:16];
}

+ (UIImage *)sysNavigationBarBack
{
    return [[LLAssetsPickerStyle bundleImage:@"LLAssetsPicker_Navigation_bar_back.png"]stretchableImageWithLeftCapWidth:1 topCapHeight:1];
}

+ (LLAssetsPickerStyle*)defaultStyle
{
    LLAssetsPickerStyle *defaultStyle = [[LLAssetsPickerStyle alloc]init];
    
    return defaultStyle;
}

+ (UIImage *)bundleImage:(NSString*)imageName
{
    NSString *bunldPath = [[NSBundle mainBundle]pathForResource:@"LLAssetsPickerResourceBundle" ofType:@"bundle"];
    NSString *imagePath = [bunldPath stringByAppendingPathComponent:imageName];
    
    return [UIImage imageWithContentsOfFile:imagePath];
}

#pragma mark - 可以重写自定义属性的getter方法

- (NSInteger)numberOfColums
{
    return 4;
}

- (CGFloat)columSpace
{
    return 3.f;
}

- (BOOL)enableBigImageShowAction
{
    return YES;
}

- (BOOL)enableAutoChooseInDetail
{
    return YES;
}

- (LLAssetsPickerCommonStyleDescription*)sysAlbumsNavigationBarDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.title = @"选择相册";
    aStyleDes.backgroundImage = [LLAssetsPickerStyle sysNavigationBarBack];
    aStyleDes.font = [LLAssetsPickerStyle sysNavigationTitleFont];
    aStyleDes.titleColor = LLQuickHexColor(@"333333");
    aStyleDes.frameSize = CGSizeMake(80, 20);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPhotoBackBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.normalStateTitle = @"选择相册";
    aStyleDes.font = [UIFont boldSystemFontOfSize:16];
    aStyleDes.normalStateTextColor = LLQuickHexColor(@"333333");
    aStyleDes.frameSize = CGSizeMake(100, 24);
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPhotoNavigationBarDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.title = @"选择照片";
    aStyleDes.backgroundImage = [LLAssetsPickerStyle sysNavigationBarBack];
    aStyleDes.font = [UIFont boldSystemFontOfSize:18];
    aStyleDes.titleColor = LLQuickHexColor(@"333333");
    aStyleDes.frameSize = CGSizeMake(80, 20);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPreviewNavigationBarDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.backgroundImage = [LLAssetsPickerStyle sysNavigationBarBack];
    aStyleDes.font = [LLAssetsPickerStyle sysNavigationTitleFont];
    aStyleDes.titleColor = LLQuickHexColor(@"333333");
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysCancelBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.normalStateTitle = @"取消";
    aStyleDes.font = [UIFont boldSystemFontOfSize:16];
    aStyleDes.normalStateTextColor = LLQuickHexColor(@"333333");
    
    return aStyleDes;
    
}

- (LLAssetsPickerCommonStyleDescription*)sysBackBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.font = [LLAssetsPickerStyle sysNavigationTitleFont];
    aStyleDes.normalStateTextColor = LLQuickHexColor(@"333333");
    aStyleDes.frameSize = CGSizeMake(80, 20);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysFinishDoneBtDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.normalStateTitle = @"确认";
    aStyleDes.highlightStateTextColor = [UIColor whiteColor];
    aStyleDes.normalStateTextColor = [UIColor whiteColor];
    aStyleDes.font = [LLAssetsPickerStyle sysButtonFont];
    aStyleDes.normalStateImage = LLQuickImageByColorWithSize(LLQuickHexColor(@"ab44a0"), CGSizeMake(100, 30));
    aStyleDes.highlightStateImage = LLQuickImageByColorWithSize(LLQuickHexColor(@"9a3d90"), CGSizeMake(100, 30));
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    aStyleDes.originPoint = CGPointMake(screenWidth-2.5-82.5, 9);
    aStyleDes.frameSize = CGSizeMake(100, 24);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPreviewBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.normalStateTitle = @"预览";
    aStyleDes.highlightStateTextColor = [LLAssetsPickerStyle sysButtonTitleHighlightColor];
    aStyleDes.normalStateTextColor = [LLAssetsPickerStyle sysButtonTitleNormalColor];
    aStyleDes.highlightStateImage = LLQuickImageByColorWithSize(LLQuickHexColor(@"e5e5e5"), CGSizeMake(100, 30));
    aStyleDes.font = [LLAssetsPickerStyle sysButtonFont];
    aStyleDes.originPoint = CGPointMake(2.5, 12);
    aStyleDes.frameSize = CGSizeMake(50,22);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPreviewChangeSelectStateBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.selectedStateImage = [LLAssetsPickerStyle bundleImage:@"标题栏icon-选中.png"];
    aStyleDes.normalStateImage = [LLAssetsPickerStyle bundleImage:@"标题栏icon-未选中.png"];
    aStyleDes.originPoint = CGPointMake(30, 5);
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPreviewBackBtnDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.normalStateImage =[LLAssetsPickerStyle bundleImage:@"标题栏icon-左箭头.png"];
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPreviewBottomToolBarDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.frameSize = (CGSize){[UIScreen mainScreen].bounds.size.width,44};
    aStyleDes.backgroundColor = [UIColor whiteColor];
    aStyleDes.backgroundImage = [LLAssetsPickerStyle bundleImage:@"底部工具栏BG.png"];
    
    return aStyleDes;
}

- (LLAssetsPickerCommonStyleDescription*)sysPhotoBottomToolBarDes
{
    LLAssetsPickerCommonStyleDescription *aStyleDes = [[LLAssetsPickerCommonStyleDescription alloc]init];
    aStyleDes.frameSize = (CGSize){[UIScreen mainScreen].bounds.size.width,48};
    aStyleDes.backgroundColor = [UIColor whiteColor];
    aStyleDes.backgroundImage = [LLAssetsPickerStyle bundleImage:@"底部工具栏BG.png"];
    
    return aStyleDes;
}

- (Class)sysOverlayViewClass
{
    return [LLAssetsPickerOverlayView class];
}

/* 处理添加自定义风格 */
+ (NSMutableDictionary *)persistStyleDict
{
    NSData *stylesData = [[NSUserDefaults standardUserDefaults]objectForKey:kLLAssetsPickerStylePersistUDF];
    if (!stylesData) {
        
        return nil;
    }
    NSMutableDictionary *styleDict = [NSKeyedUnarchiver unarchiveObjectWithData:stylesData];
    
    return styleDict;
}

+ (void)savePersistDict:(NSMutableDictionary*)styleDict
{
    if (!styleDict) {
        return;
    }
    
    NSData *stylesData = [NSKeyedArchiver archivedDataWithRootObject:styleDict];
    [[NSUserDefaults standardUserDefaults]setObject:stylesData forKey:kLLAssetsPickerStylePersistUDF];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

+ (void)appendCustomStyle:(LLAssetsPickerStyle*)aCustomStyle forKey:(NSString *)customStyleKey
{
    if (!customStyleKey || !aCustomStyle || ![aCustomStyle isKindOfClass:[LLAssetsPickerStyle class]]) {
        return;
    }
    
    NSMutableDictionary *styles = [LLAssetsPickerStyle persistStyleDict];
    if (!styles) {
        styles = [NSMutableDictionary dictionary];
    }
    
    [styles setObject:aCustomStyle forKey:customStyleKey];
    
    [LLAssetsPickerStyle savePersistDict:styles];
}


+ (LLAssetsPickerStyle*)styleByKey:(NSString *)customStyleKey
{
    if (!customStyleKey) {
        return nil;
    }
    
    NSMutableDictionary *styles = [LLAssetsPickerStyle persistStyleDict];
    
    
    return [styles objectForKey:customStyleKey];
}

+ (void)removeCustomStyleByKey:(NSString *)customStyleKey
{
    if (!customStyleKey) {
        return;
    }
    
    NSMutableDictionary *styles = [LLAssetsPickerStyle persistStyleDict];
    
    [styles removeObjectForKey:customStyleKey];
    
    [LLAssetsPickerStyle savePersistDict:styles];
}

+ (NSArray *)existCustomStyleKeys
{
    NSMutableDictionary *styles = [LLAssetsPickerStyle persistStyleDict];
    
    return [styles allKeys];
}

+ (void)clearAllCustomStyles
{
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:kLLAssetsPickerStylePersistUDF];
}

#pragma mark - NSCoding
- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    
}

@end
